package com.web.music.portal.mvc;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.web.music.model.Person;

public class PersonFormValidator implements Validator{

	public boolean supports(Class givenClass){
		return givenClass.equals(Person.class);
	}

	public void validate(Object obj, Errors errors){
		Person person = (Person)obj;

		if (person == null){
			errors.reject("error.nullpointer", "Null data received");
		}
		else{
			if (person.getName().equals("")){
				errors.rejectValue("name", "error.empty", "Name is required!"); 
			}
			if (person.getSurname().equals("")){
				errors.rejectValue("surname", "error.empty", "Surname is required!");
			}
		}
	}
}